function Page (param){
	if(!param) param={};
	this.rp = 24;
	this.btnCnt = 6;
	this.domId = param.domId;
	if(param.rp)
		this.rp = param.rp;
	this.pageth = 1;
	this.doJumpPage = param.doJumpPage;
	
	
}
Page.prototype.createPageItemTag = function(pojo){
	var a = new Tag("a");
	if(pojo.value != this.pageth)
		a.href('javascript:void(0)').html(pojo.text).onclick(pojo.onclick);
	else{
		return new Tag("span").html(pojo.text).toDom();
	}
	return a.toDom();
}

Page.prototype.refresh = function(){
	$('#domId').html('');
	var items = this.getPageItems();
	var self = this;
	DomUtil.addDomByArray(this.domId,items,function(pojo){
		return self.createPageItemTag(pojo);
	});
}

Page.prototype.setTotal = function(total){
	this.total = total;
	this.refresh();
}

Page.prototype.setPageth = function(value){
	this.pageth = value;
	this.refresh();
}

Page.prototype.getPageth = function(){
	return this.pageth;
}

Page.prototype.calMaxPageItemCnt = function(){
	return this.btnCnt+2;
}

Page.prototype.getPageItems = function(){
	var ret = [];
	var pageCnt = this.calPageCnt();
	if(!this.total || pageCnt==1 ) return ret;
	if(this.pageth!=1){
		
		ret.push(this.createPre());
	}
	
	if(this.calMaxPageItemCnt()>=pageCnt){
		for(var i=0;i<pageCnt;i++){
			ret.push(this.createPageItem(i+1));
		}
	}else{
		var page = this.pageth;
		ret.push(this.createPageItem(1));
		var halfBtnCnt = parseInt(this.btnCnt/2);
		if(page-1<=halfBtnCnt ){
			for(var i=2;i<=this.btnCnt+1;i++){
				ret.push(this.createPageItem(i));
			}
			ret.push(this.createNovalidItem())
		}else if((pageCnt-page)<=halfBtnCnt){
			ret.push(this.createNovalidItem());
			for(var i=0;i<this.btnCnt;i++){
				ret.push(this.createPageItem(pageCnt-this.btnCnt+i));
			}
		}else{
			ret.push(this.createNovalidItem());
			for(var i=0;i<this.btnCnt;i++){
				
				ret.push(this.createPageItem(this.pageth-halfBtnCnt+i+1));
			}
			ret.push(this.createNovalidItem());
			
		}
		ret.push(this.createPageItem(this.calPageCnt()));
	}
	if(this.pageth!=this.calPageCnt()){
		ret.push(this.createNext());
	}
	return ret;
	
}

Page.prototype.createNovalidItem = function(){
	return {
		text:"..."
	}
}

Page.prototype.createPageItem = function(page){
	var self = this;
	return {
		text:page,
		value:page,
		onclick:function(){
			self.go2Page(page);
		}
	}
}

Page.prototype.createPre = function(){
	var self = this;
	return {
		text:'上一页',
		onclick:function(){
			self.go2Page(self.pageth-1);
		}
	}
}

Page.prototype.createNext = function(){
	var self = this;
	return {
		text:'下一页',
		onclick:function(){
			self.go2Page(self.pageth+1);
		}
	}
}

Page.prototype.go2Page= function(pageth){
	this.pageth = pageth;
	if(this.doJumpPage){
		this.doJumpPage(pageth);
	}
}


Page.prototype.calPageCnt = function(){
	if(this.total==0) return 0;
	if(this.rp == 0){
		return 1;
	}
	else {
		return parseInt((this.total-1)/this.rp)+1;
	};
}

Page.prototype.getPageCondition=function(){
	return {
		page:this.pageth
	}
}